package com.naton.mydemo.viewmodel

import androidx.lifecycle.MutableLiveData
import com.naton.common.callback.DataCallback
import com.naton.common.network.ApiErrorModel
import com.naton.common.viewmodel.BaseViewModel
import com.naton.mydemo.bean.User
import com.naton.mydemo.model.repository.LoginRepository

/**
 * 登录
 */
class LoginViewModel : BaseViewModel() {

    var loginRepository : LoginRepository? = LoginRepository()

    //登录信息
    private val loginUserLivaData: MutableLiveData<User> = MutableLiveData()

    fun getLoginUserLiveData(): MutableLiveData<User>{
        return loginUserLivaData
    }

    /**
     * 登录
     */
    fun login(telephone : String , password : String) {
        showProgress()
        loginRepository?.login(telephone , password , object : DataCallback<User> {
            override fun success(data: User?) {
                hideProgress()
                showToast(data.toString())
                loginUserLivaData.value = data
            }

            override fun failure(statusCode: Int, apiErrorModel: ApiErrorModel) {
                hideProgress()
                val user = User()
                user.telephone = "测试"
                user.companyFullName = "ok"
                showToast(user.toString())
                loginUserLivaData.value = user
            }
        })

    }
}